<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>明细管理</title>
<#include "../common/link.ftl"/>
    <script>
        $(function () {
            $('.btn-input').click(function () {
                //清空表单元素的数据
                $("input").val("");
                //获取到按钮上的json数据,通过data方法转换成js对象
                var json = $(this).data("json");
                console.log(json);
                if (json) {
                    //将数据填充到表单中
                    $('input[name=id]').val(json.id);
                    $('input[name=title]').val(json.title);
                    $('input[name=sequence]').val(json.sequence);
                }
                $('input[name=name]').val('${(parent.title)!}');
                $('input[name=parentId]').val(${(parent.id)!});

                //打开模态框
                $('#editModal').modal("show");
            })


            $('.btn-submit').click(function () {
                //将表单的请求方式修改为异步请求
                //后台一定是响应json字符串回来
                $('#editForm').ajaxSubmit(function (data) {
                    console.log(data);
                    if (data.success) {
                        $.messager.alert("温馨提示", "执行成功,2s后自动刷新");
                        //2秒后自动关闭
                        setTimeout(function () {
                            //刷新本页面
                            window.location.reload();
                        }, 1600);
                        alert("恭喜你,保存成功");
                    } else {
                        $.messager.alert(data.msg);
                    }
                })
            })

            $(".btn-delete").click(function () {
                var url = $(this).data("url");
                $.messager.confirm("温馨提示", "您确定删除当前数据吗", function () {
                    //使用ajax发送请求
                    $.get(url, function (data) {
                        if (data.success) {
                            $.messager.alert("温馨提示", "执行成功,2s后自动刷新");
                            //2秒后自动关闭
                            setTimeout(function () {
                                //刷新本页面
                                window.location.reload();
                            }, 1600);
                            alert("恭喜你,删除成功");
                        } else {
                            $.messager.alert("温馨提示", data.msg);
                        }
                    })
                })
            })
        })

    </script>

</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
<#include "../common/navbar.ftl"/>
    <!--菜单回显-->
<#assign currentMenu="systemDictionaryItem"/>
<#include "../common/menu.ftl"/>
    <div class="content-wrapper">
        <section class="content-header">
            <h1>明细管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <div class="row">
                    <div class="col-sm-3">
                        <div class="panel panel-info">
                            <div class="panel-heading"><strong>字典明细</strong></div>
                            <ul class="list-group" id="dicDirUl">
                            <#list dics as dic>
                                <li class="list-group-item"><a class="dicDir" data-pid="${dic.id}" href="/systemDictionaryItem/list.do?parentId=${dic.id}">${dic.title}</a></li>
                            </#list>

                                <script>
                                    $(".dicDir[data-pid='${(qo.parentId)!}']").closest("li").addClass("active");
                                    $(".dicDir[data-pid='${(qo.parentId)!}']").css("color", "white")
                                </script>
                            </ul>
                        </div>
                    </div>
                    <div class="col-sm-9">

                        <#if pageResult??>
                        <!--高级查询--->
                        <form class="form-inline" id="searchForm" action="/systemDictionaryItem/list.do" method="post">
                        <#--分页查询的关键-->
                            <input type="hidden" name="currentPage" id="currentPage" value="1">
                            <input type="hidden" name="parentId" id="parentId" value="${qo.parentId}">
                            <a href="javascript:;" class="btn btn-success btn-input" style="margin: 10px">
                                <span class="glyphicon glyphicon-plus"></span> 添加
                            </a>
                        </form>
                        <!--编写内容-->
                        <div class="box-body table-responsive no-padding ">
                            <table class="table table-hover table-bordered">
                                <tr>
                                    <th>编号</th>
                                    <th>明细名称</th>
                                    <th>明细编号</th>
                                    <th>操作</th>
                                </tr>
                            <#--list,要遍历的集合 as 变量-->
                    <#list pageResult.list as entity>
                        <tr>
                        <#--从0开始,需要加1-->
                            <td>${entity_index + 1}</td>
                            <td>${(entity.title)!}</td>
                            <td>${(entity.sequence)!}</td>
                            <td>
                                <a class="btn btn-info btn-xs btn-input" href="javascript:;"
                                   data-json='${entity.jsonString}'>
                                    <span class="glyphicon glyphicon-pencil"></span> 编辑
                                </a>
                                <a href="javascript:;" data-url="/systemDictionaryItem/delete.do?id=${entity.id}"
                                   class="btn btn-danger btn-xs btn-delete">
                                    <span class="glyphicon glyphicon-trash"></span> 删除
                                </a>
                            </td>
                        </tr>
                    </#list>
                            </table>
                            <!--分页-->
                <#include "../common/page.ftl"/>
                        </div>
                        </#if>
                    </div>
                </div>

            </div>
        </section>
    </div>
<#include "../common/footer.ftl"/>
</div>


<!-- Modal -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">明细添加/编辑</h4>
            </div>
            <div class="modal-body">
                <form action="/systemDictionaryItem/saveOrUpdate.do" method="post" id="editForm">
                    <input name="id" type="hidden">
                    <div class="form-group">
                        <label for="exampleInputEmail1">字典目录</label>
                        <input type="text" class="form-control" id="inputDeptName" name="name" placeholder="明细名称" readonly>
                        <input name="parentId" type="hidden" class="form-control">
                    </div>
                    <div class="form-group">
                        <label for="exampleInputPassword1">明细标题</label>
                        <input type="text" class="form-control"  name="title" placeholder="请输入明细编号">
                    </div>
                    <div class="form-group">
                        <label for="exampleInputPassword1">明细序号</label>
                        <input type="text" class="form-control"  name="sequence" placeholder="请输入明细序号">
                    </div>
                </form>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary btn-submit">保存</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>

